import React from 'react'
import PropTypes from 'prop-types'
import { Form, Input } from 'antd'

export default class AddForm extends React.Component {
    static propTypes = {
        setAddForm: PropTypes.func.isRequired, // 用来传递form对象的函数 
    }

    abc = React.createRef()

    state={roleName:''}

    onChange=(e)=>{
       this.setState({roleName:e.target.value})
    }
    

    UNSAFE_componentWillMount(){
        this.props.setAddForm(this.abc)
    }
     
    render() {
        return (
            <Form ref={this.abc} >
                <Form.Item label='角色名称' name='roleName' labelCol={{span:4}} wrapperCol={{span:15}}  rules={
                      [
                        ({ getFieldValue }) =>
                           ({validator(role,value){
                             if(!value){
                             return Promise.reject('角色名称必须输入')
                             }
                            //  else if(!validate_password(value)){
                            //  return Promise.reject('商品名称不正确')
                        //  }
                             return Promise.resolve()
                         }}) 
                        
                         
                    ]
                   }>
                    <Input onChange={this.onChange}  placeholder='请输入角色名称'/>
                </Form.Item>
            </Form>
        )
    }
}

